﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Frontdatabase.Migrations
{
    /// <inheritdoc />
    public partial class 添加视频分区和类别表 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Categories",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false, comment: "自增主键")
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false, comment: "类别名 如:电影,电视剧,纪录片"),
                    Route = table.Column<string>(type: "nvarchar(max)", nullable: false, comment: "页面路由"),
                    Isgeneral = table.Column<bool>(type: "bit", nullable: false, comment: "是不是普通的类别 默认是;如: 电影 电视剧 番剧 就是不是普通类别;游戏 音乐 知识等就是普通类别"),
                    Create_Time = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间"),
                    UpDate_Time = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "更新时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Categories", x => x.Id);
                },
                comment: "类别表 如:电影 电视剧 纪录片");

            migrationBuilder.CreateTable(
                name: "SubAreas",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false, comment: "自增主键")
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false, comment: "分区名"),
                    Route = table.Column<string>(type: "nvarchar(max)", nullable: false, comment: "页面路由"),
                    Synopsis = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true, comment: "分区简介"),
                    CategoryId = table.Column<int>(type: "int", nullable: false),
                    Create_Time = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间"),
                    UpDate_Time = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "更新时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SubAreas", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SubAreas_Categories_CategoryId",
                        column: x => x.CategoryId,
                        principalTable: "Categories",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "分区表 一个分区对应一个类别,一个类别对应多个分区");

            migrationBuilder.CreateIndex(
                name: "IX_Categories_Name",
                table: "Categories",
                column: "Name",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_SubAreas_CategoryId",
                table: "SubAreas",
                column: "CategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_SubAreas_Name_CategoryId",
                table: "SubAreas",
                columns: new[] { "Name", "CategoryId" },
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SubAreas");

            migrationBuilder.DropTable(
                name: "Categories");
        }
    }
}
